home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / share / doc / python-gnome2-desktop / examples / gnomeprint / example_09.py < prev    next >
Encoding:
Python Source  |  2009-03-14  |  2.0 KB  |  67 lines

  1. #! /usr/bin/env python
  2. #
  3. # *  example_09.c: sample gnome-print code. This dialog saves the GnomePrintConfig
  4. # *                to disk after printing and loads it before creating the dialog
  5. # *                This shows how to implement persistent print configuration.
  6. # *
  7. # *  This program is free software; you can redistribute it and/or
  8. # *  modify it under the terms of the GNU Library General Public License
  9. # *  as published by the Free Software Foundation; either version 2 of
  10. # *  the License, or (at your option) any later version.
  11. # *
  12. # *  This program is distributed in the hope that it will be useful,
  13. # *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. # *  GNU Library General Public License for more details.
  16. # *
  17. # *  You should have received a copy of the GNU Library General Public
  18. # *  License along with this program; if not, write to the Free Software
  19. # *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20. # *
  21. # *  Authors:
  22. # *    Chema Celorio <chema@ximian.com>
  23. #    Python conversion:
  24. #      Gustavo J. A. M. Carneiro <gustavo@users.sf.net>
  25. # *
  26. # *  Copyright (C) 2002 Ximian Inc. and authors
  27. # *
  28. # */
  29.  
  30. #/*
  31. # * See README
  32. # */
  33.  
  34. import pygtk; pygtk.require("2.0")
  35. import gnomeprint, gnomeprint.ui
  36.  
  37. CONFIG_FILE  = "print_config"
  38.  
  39. def my_config_load_from_file():
  40.     try:
  41.     file_ = file(CONFIG_FILE)
  42.     except IOError:
  43.     print "Config not found"
  44.     return gnomeprint.config_default()
  45.     return gnomeprint.config_from_string(file_.read(), 0)
  46.  
  47. def my_config_save_to_file(config):
  48.     file(CONFIG_FILE, "w").write(config.to_string(0))
  49.  
  50.     
  51. def my_print():
  52.     config = my_config_load_from_file()
  53.     job = gnomeprint.Job(config)
  54.     dialog = gnomeprint.ui.Dialog(job, "Example 09 print dialog", 0)
  55.     response = dialog.run()
  56.     if response == gnomeprint.ui.DIALOG_RESPONSE_CANCEL:
  57.     print "Printing was canceled, config not saved"
  58.     return
  59.     
  60.     print "Config saved to \"%s\"" % CONFIG_FILE
  61.     my_config_save_to_file(config)
  62.  
  63. my_print()
  64.  
  65. print "Done..."
  66.  
  67.